package com.sdry.service.jyy;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sdry.mapper.jyy.ShedudetailMapper;
import com.sdry.mapper.llm.ClassesMapper;
import com.sdry.model.jyy.Shedudetail;
import com.sdry.model.jyy.ShedudetailExample;
import com.sdry.model.jyy.ShedudetailExample.Criteria;
import com.sdry.model.llm.Classes;
import com.sdry.model.llm.Team;

@Service
@Transactional
public class ShedudetailServiseImpl implements ShedudetailServise{

	@Resource
	private ShedudetailMapper shedudetailMapper;
	@Resource
	private ClassesMapper classesMapper;
	
	@Override
	public int countByExample(ShedudetailExample example) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteByExample(ShedudetailExample example) {
		return shedudetailMapper.deleteByExample(example);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insert(Shedudetail record) {
		return shedudetailMapper.insert(record);
	}

	@Override
	public int insertSelective(Shedudetail record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Shedudetail> selectByExampleWithBLOBs(ShedudetailExample example) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Shedudetail> selectByExample(ShedudetailExample example) {
		return shedudetailMapper.selectByExample(example);
	}

	@Override
	public List<Shedudetail> selectByExampleWithBLOBsForStartPage(
			ShedudetailExample example, Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Shedudetail> selectByExampleForStartPage(
			ShedudetailExample example, Integer pageNum, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Shedudetail> selectByExampleWithBLOBsForOffsetPage(
			ShedudetailExample example, Integer offset, Integer limit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Shedudetail> selectByExampleForOffsetPage(
			ShedudetailExample example, Integer offset, Integer limit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Shedudetail selectFirstByExample(ShedudetailExample example) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Shedudetail selectFirstByExampleWithBLOBs(ShedudetailExample example) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Shedudetail selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Shedudetail selectByPrimaryKey(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int updateByExampleSelective(Shedudetail record,
			ShedudetailExample example) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByExampleWithBLOBs(Shedudetail record,
			ShedudetailExample example) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByExample(Shedudetail record, ShedudetailExample example) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKeySelective(Shedudetail record) {
		ShedudetailExample example = new ShedudetailExample();
		Criteria createCriteria = example.createCriteria();
		createCriteria.andIdEqualTo(record.getId());
		return shedudetailMapper.updateByExampleSelective(record, example );
	}

	@Override
	public int updateByPrimaryKeyWithBLOBs(Shedudetail record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKey(Shedudetail record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteByPrimaryKeys(String ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteByPrimaryKeys2(String ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void initMapper() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String selectDaysheduTime(Team team) {
		
		//获取当前时间
		Date date = new Date();
		SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowTime = sdf3.format(date);
		Integer hourse = Integer.parseInt(nowTime.substring(11,13));
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = "";
		
		//根据班次查询工作时间
		List<Classes> classesByName = classesMapper.getClassesByName(team.getCrew());
		Classes cla = classesByName.get(0);
		List<Classes> classesByWrite = classesMapper.getClassesByName("白班");
		Classes clas = classesByWrite.get(0);
		Integer writeStart = Integer.parseInt(clas.getStartTime().substring(0, 2));
		String startTime = cla.getStartTime();
		String endTime = cla.getEndTime();
		Integer start = Integer.parseInt(startTime.substring(0, 2));
		Integer end = Integer.parseInt(endTime.substring(0, 2));
		//如果是晚班的24点之后登录，验证上一天的排产单
		if(start > end && hourse <= end){
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
			ca.setTime(date); //设置时间为当前时间
			ca.add(Calendar.DATE, -1);
			Date last = ca.getTime();
			time = sdf.format(last);
		}else if(start < end && start < writeStart){
			Calendar ca = Calendar.getInstance();//得到一个Calendar的实例 
			ca.setTime(date); //设置时间为当前时间
			ca.add(Calendar.DATE, -1);
			Date last = ca.getTime();
			time = sdf.format(last);
		}else{
			time = sdf.format(date);
		}
		
		//时间
		team.setRemark01(time);
		return shedudetailMapper.selectDaysheduTime(team);
	}

	@Override
	public Shedudetail selectById(Long id) {
		return shedudetailMapper.selectById(id);
	}


}
